package com.mark.web.sys.controller.backend;

import com.mark.common.ServerResponse;
import com.mark.web.sys.entity.from.ResourceFrom;
import com.mark.web.sys.entity.po.Resource;
import com.mark.web.sys.service.IResourceService;
import com.mark.web.sys.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Objects;

/**
 * @Description: 用户头像POJO类
 * @Author: Mark
 * @CreateDate: 2019/1/13 20:19
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
@Api(tags = "系统-后台-资源模块")
@RestController
@RequestMapping("/sys/resource/")
public class ResourceController {

    @Autowired
    private IResourceService iResourceService;

    @ApiOperation(value = "添加资源")
    @PostMapping("add.do")
    public ServerResponse<String> addResource(@Valid ResourceFrom resourceFrom, BindingResult result){
        if(result.hasErrors()){
            return ServerResponse.createByErrorMessage(Objects.requireNonNull(result.getFieldError()).getDefaultMessage());
        }
        Resource resource = new Resource();
        BeanUtils.copyProperties(resourceFrom,resource);
        return iResourceService.addResource(resource);
    }
}
